package com.lb.shopguide.ui.view;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageButton;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.lb.shopguide.R;


/**
 * author：zhangxy
 * time：2016/12/1  14:18.
 * descr：
 */

public class NormalTitleBar extends RelativeLayout {
    private TextView tvTitle;
    private ImageButton ivLeft;
    private ImageButton ivRight;
    private TextView tvRight;
    private RelativeLayout layoutRoot;

    private Context context;

    public NormalTitleBar(Context context) {
        super(context, null);
        this.context = context;
    }

    public NormalTitleBar(Context context, AttributeSet attrs) {
        super(context, attrs);
        this.context = context;
        View view = LayoutInflater.from(context).inflate(R.layout.bar_normal, this);
        ivLeft = view.findViewById(R.id.image_left);
        tvTitle = view.findViewById(R.id.tv_title);
        ivRight = view.findViewById(R.id.image_right);
        tvRight = view.findViewById(R.id.tv_right);
        layoutRoot = view.findViewById(R.id.common_title);
    }


    public void setTitleText(String string) {
        tvTitle.setText(string);
    }

    public void setTitleText(int string) {
        tvTitle.setText(string);
    }

    public void setTitleColor(int color) {
        tvTitle.setTextColor(color);
    }

    /**
     * 左图标
     *
     * @param id
     */
    public void setLeftImageSrc(int id) {
        ivLeft.setVisibility(View.VISIBLE);
        ivLeft.setImageResource(id);
    }

    public void setRightImageSrc(int id) {
        ivRight.setVisibility(VISIBLE);
        ivRight.setImageResource(id);
    }

    public void setRightText(String text) {
        tvRight.setVisibility(VISIBLE);
        tvRight.setText(text);
    }

    public void setBackground(int color) {
        layoutRoot.setBackgroundColor(color);
    }

    /*
     * 点击事件
     */
    public void setOnLeftImageListener(OnClickListener listener) {
        ivLeft.setOnClickListener(listener);
    }

    public void setOnRightImageListener(OnClickListener listener) {
        ivRight.setOnClickListener(listener);
    }

    public void setOnRightTextListener(OnClickListener listener) {
        tvRight.setOnClickListener(listener);
    }
}
